package com.macasa.panel.entity.impl;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.enumerations.StunnelType;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.IStunnelService;

@Entity
@Table(name = "stunnel_server_service")
@Getter
@Setter
@ToString(callSuper = true)
public class StunnelService extends Service implements IStunnelService {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= -5493555519984243355L;

	@Column(name = "accept", nullable = false)
	private String				accept;

	@Column(name = "connect", nullable = false)
	private String				connect;

	@Enumerated(EnumType.STRING)
	@Column(name = "type", nullable = false)
	private StunnelType			type;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof StunnelService)) {
			return false;
		}

		final StunnelService other = CastHelpers.cast(obj, StunnelService.class);

		return super.equals(obj) && Objects.equal(this.accept, other.accept) && Objects.equal(this.connect, other.connect)
				&& Objects.equal(this.type, other.type);
	}

	@Override
	public int hashCode() {
		return super.hashCode() + Objects.hashCode(this.accept, this.connect, this.type);
	}
}
